package com.clw.weblogin.service.impl;

import com.clw.weblogin.common.entity.ResultEntity;
import com.clw.weblogin.dao.UserMapper;
import com.clw.weblogin.entity.User;
import com.clw.weblogin.entity.UserExample;
import com.clw.weblogin.service.HuanKuanLiuShuiService;
import com.clw.weblogin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    public ResultEntity login(User user) {
        ResultEntity resultEntity=new ResultEntity();
        //Example类指定如何构建一个动态的where子句.
        UserExample example=new UserExample();
        //创建SQL语句条件对象
        UserExample.Criteria criteria=example.createCriteria();
        //添加SQL语句where子句的条件：相当于 select * from tb_user where username=123 and password=123;
        criteria.andUsernameEqualTo(user.getUsername());
        criteria.andTypeNotEqualTo(1);
        criteria.andPasswordEqualTo(user.getPassword());
        example.or(criteria);
        //执行查询，返回结果
        List<User> list=userMapper.selectByExample(example);
        if(list.size()>0){
            resultEntity.setState(200);
            resultEntity.setMessage("登录成功");
            resultEntity.setData(list.get(0));
        }else{
            resultEntity.setMessage("登录失败");
        }
        return resultEntity;
    }
}
